<?php
    $model = Mage::getModel('systempoint/log');
    $logs = $model->getCollection();
    //->addFieldToFilter('email', array('like' => "%{$this->getEmail()}"));

    $menbership = Mage::getModel('systempoint/membership')
        ->getCollection()
        ->setOrder('number_of_point', 'ASC');
        //->addFieldToFilter('email', array('like' => "%{$customer->getUsername()}"));
    /*
    $point = 0;
    foreach($logs as $item){
        if(stristr($item->getUserEmail(), $this->getCustomer()->getEmail()) !== false){
            $point += $item->getPoint();
        }
    }
    */
    $point = Mage::getModel('systempoint/userpoint')
        ->getCollection()
        ->addFieldToFilter('email', array('eq' => "{$this->getCustomer()->getEmail()}"))
        ->getFirstItem()
        ->getUserPoint();

    $member = $menbership->getFirstItem();
    foreach($menbership as $ms){
        if($point >= $ms->getNumberOfPoint()){
            $member = $ms;
        }
    }
    $nextMember = null;
    $mPoint = $member->getNumberOfPoint();
    foreach($menbership as $ms){
        if($mPoint < $ms->getNumberOfPoint()){
            $nextMember = $ms;
            break;
        }
    }
    $last = $menbership->getLastItem();
    if($nextMember->getNumberOfPoint() == $last->getNumberOfPoint()){
        $nextMember = $last;
    }
?>

<div class="min-side">
    <h5><?php echo $this->__('Min konto'); //MIN SIDE ?></h5>
    <div class="min-box-2">
        <h6><?php echo $this->__('Personlig information') ?></h6>
        <?php echo $this->getChildHtml('info') ?>
    </div>

    <div class="clr">&nbsp;</div>
    <div class="member-status">
        <img src="<?php echo $member->getIconPath() ?>" alt=""/>
        <h6>Medlemsstatus</h6>
        <p>
            Du er <?php echo $member->getTitle() ?>, og har optjent <?php echo $point ?> point. Du får <?php echo $member->getPercentDiscount() ?>% RABAT på alle produkter af den normale udsalgspris.
            Når du har optjent <?php echo $nextMember->getNumberOfPoint() - $point ?> point mere bliver du automatisk <?php echo $nextMember->getTitle() ?> og får <?php echo $nextMember->getPercentDiscount() ?>% RABAT på alle produkter af den normale udsalgspris.
        </p>
    </div>
    <h6>Ordrehistorik</h6>
    <table class="table-price mt20" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td style="border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;width:24px;"></td>
            <td style="text-align:left; width:105px;border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;">Dato</td>
            <td style="text-align:left; width:160px;border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;">Produkt</td>
            <td style="text-align:center;border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;">Ordrenr</td>
            <td style="text-align:center;border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;">Point</td>
        </tr>
        <?php foreach($logs as $item){ ?>
            <?php if(stristr($item->getUserEmail(), $this->getCustomer()->getEmail()) !== false){ ?>
                <tr>
                    <td class="w-22"><img src="<?php echo $item->getIcon() ?>" alt=""/></td>
                    <td><?php echo date('d-m-Y', strtotime($item->getLogDate())) ?></td>
                    <td><?php echo $item->getTitle() ?></td>
                    <td style="text-align:center;"><?php echo $item->getOrderId() ?></td>
                    <td style="text-align:center;"><?php echo $item->getPoint() ?></td>
                </tr>
            <?php } ?>
        <?php } ?>

        <tr>
            <td colspan="4" style="border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;"><b><?php echo $member->getTitle() ?>, total  score:</b></td>
            <td style="text-align:center;border-bottom:1px #3b3b3b solid; border-top:1px #3b3b3b solid;"><b><?php echo $point ?></b></td>
        </tr>
    </table>
    <div class="mt20">
        <a style="margin-left:0;" class="btn-social" href="<?php echo $this->getUrl('') ?>">GÅ TIL SHOPPEN</a>
    </div>
</div>






<?php if(1==0){ ?>
<div class="dashboard">
    <div class="page-title">
        <h1><?php echo $this->__('MIN SIDE') ?></h1>
    </div>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <?php echo $this->getChildHtml('hello') ?>
    <?php echo $this->getChildHtml('top') ?>
    <div class="box-account box-info roundcorner">
        <div class="box-head">
            <h2><?php echo $this->__('Account Information') ?></h2>
        </div>
        <?php echo $this->getChildHtml('info') ?>
        <?php echo $this->getChildHtml('address') ?>
    </div>
    <?php echo $this->getChildHtml('info1') ?>
    <?php echo $this->getChildHtml('info2') ?>
</div>
<?php } ?>